<html>
    
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        
        <link rel="stylesheet" type="text/css" href='../public/css/style.css'>
        <title>Nguyen Quoc Thong</title>
      
 <body id="khung">
        <div id="banner">
            
        </div>

        <div id="menu">
            <ul id="a">
                <li><a href="#">Home</a>  </li>
                <li><a href="#">About Us</a> </li>
                <li><a href="#">Forums</a> </li>
                <li><a href="#">Contact</a> </li>

            </ul>
        </div>




        <div id="page">     
          <?php
      
        require_once '../model/db.php';
        require_once '../model/keywords.php';
        require_once '../model/works.php';
        $works = new works();
        
        ?>       
        <br>
       <div style="position: fixed; width: 100px; margin:auto;">
        <div id="list">
       <?php $page = $works->count() / PER_PAGE; ?>
        <a href='index.php?page=<?php echo $_GET["page"] - 1?>'> < </a>  
        <a href='index.php?page=1'> Trang Đầu </a>
     
        <?php for ($i = 1; $i <= 7; $i++): ?>
            <?php if (($_GET["page"] == 1) || ($_GET["page"] == 2) || ($_GET["page"] == 3) || ($_GET["page"] == 4)): ?>            
                <?php for ($i = 1; $i <= 7; $i++): ?>
                    <a href='index.php?page=<?php echo $i; ?> '><?php echo $i ?></a>
                    <?php if ($_GET["page"] == $i): ?>
                        <?php $works->start = (($i - 1) * 50); ?>
                        <?php $works->end = PER_PAGE; ?>
                    <?php endif; ?>
                <?php endfor; ?>

            <?php elseif (($_GET["page"] == $page) || ($_GET["page"] == $page - 1) || ($_GET["page"] == $page - 2) || ($_GET["page"] == $page - 3)): ?>        
                <?php for ($i = $page - 7; $i <= $page; $i++): ?>
                    <a href='index.php?page=<?php echo $i; ?> '><?php echo $i ?></a>
                    <?php if ($_GET["page"] == $i): ?>
                        <?php $works->start = (($i - 1) * 50); ?>
                        <?php $works->end = PER_PAGE; ?>
                    <?php endif; ?>
                <?php endfor; ?>

            <?php else : ?>
                <?php for ($i = $_GET["page"] - 3; $i <= $_GET["page"] + 3; $i++): ?>
                    <a href='index.php?page=<?php echo $i; ?> '><?php echo $i ?></a>
                    <?php if ($_GET["page"] == $i): ?>
                        <?php $works->start = (($i - 1) * 50); ?>
                        <?php $works->end = PER_PAGE; ?>
                    <?php endif; ?>
                <?php endfor; ?>
            <?php endif; ?> 
        <?php endfor; ?>   

                  
        <a href='index.php?page=<?php echo $page; ?>'> Trang Cuối </a> 

        
        <a href='index.php?page=<?php echo $_GET["page"] + 1?>'>> </a>
      
        
       
        <?php $list_of_works = $works->select(); ?>
</div>
            </div>
        <br>
       
        <table border="1px">
           <form method="post"      enctype="multipart/form-data">
    <label for="file">Filename:</label>
    <input type="file" name="file" id="file"><br>
    <input type="submit" name="submit" value="Submit">
</form>


<?php
if (isset($_POST['submit'])) {
    $allowedExts = array("gif", "jpeg", "jpg", "png");
    $temp = explode(".", $_FILES["file"]["name"]);
    $extension = end($temp);
    if ((($_FILES["file"]["type"] == "image/gif")
            || ($_FILES["file"]["type"] == "image/jpeg")
            || ($_FILES["file"]["type"] == "image/jpg")
            || ($_FILES["file"]["type"] == "image/pjpeg")
            || ($_FILES["file"]["type"] == "image/x-png")
            || ($_FILES["file"]["type"] == "image/png"))
//            && ($_FILES["file"]["size"] < 2000000)
            && in_array($extension, $allowedExts)) {
        if ($_FILES["file"]["error"] > 0) {
            echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
        } else {
            echo "Upload: " . $_FILES["file"]["name"] . "<br>";
            echo "Type: " . $_FILES["file"]["type"] . "<br>";
            echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
            echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";

            if (file_exists("images/" . $_FILES["file"]["name"])) {
                echo $_FILES["file"]["name"] . " Upload thành công  . ";
            } else {
                
                move_uploaded_file($_FILES["file"]["tmp_name"], "images/" . $_FILES["file"]["name"]);
                echo "Stored in: " . "images/" . $_FILES["file"]["name"];
            }
             $url= "images/" . $_FILES["file"]["name"];
           
             echo "<img src='$url' width='120' /><br />";
        }
        
    } else {
        echo "Invalid file";
        
    }
}
?>

            <tr>
                <td>STT </td>
                <td>Công Việc </td>
                <td>Link</td>
            </tr>
            <?php foreach ($list_of_works as $list1): ?>
                <tr>
                    <td><?php echo $list1["id"]; ?></td>
                    <td><?php echo $list1["name"]; ?></td>
                    <td><a href='<?php echo $list1["url"]; ?>'><?php echo $list1["url"]; ?></td>
                </tr>
            <?php endforeach; ?>
        </table>
        </br>
       
    </body>
</html>
